package hhm.framessm.authority.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import hhm.framessm.authority.service.UserService;
import hhm.framessm.common.pojo.FBResult;
import hhm.framessm.pojo.TbUser;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ResponseBody
	public FBResult login(String username, String password, HttpServletRequest request, HttpServletResponse response) {

		TbUser user = userService.login(username, password);
		if (user != null) {
			request.getSession().setAttribute("user", user);

			return FBResult.build(200, null);

		} else {
			return FBResult.build(300, null);

		}
	}
}